package com.cjjd.c.feature.home;

import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.cjjd.c.R;
import com.cjjd.c.ShareKeys;
import com.cjjd.c.base.MyBaseAdapter;
import com.cjjd.c.bean.HotelListItemBean;
import com.cjjd.c.utils.SharePrefUtil;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * ----------------------------------
 * Created by xyd on 2017/9/11.
 * <p/>
 * 描  述：
 * <p/>
 * 修订历史:
 * ----------------------------------
 */

public class SelectHotelAdapter extends MyBaseAdapter {
    public SelectHotelAdapter(FragmentActivity mContext) {
        super(mContext);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_select_hotel, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        final HotelListItemBean itemBean = (HotelListItemBean) getItem(position);
        viewHolder.tvHotelName.setText(itemBean.hotelName);
        viewHolder.tvOrderNum.setText("订单号：" + itemBean.orderId);
        viewHolder.btnIntoHotel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharePrefUtil.saveString(mContext, ShareKeys.HomeTittleName, itemBean.hotelName);
                SharePrefUtil.saveString(mContext, ShareKeys.HomeHotelUuid, itemBean.hotelUuid);
                mContext.onBackPressed();

            }
        });

        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.tv_hotel_name)
        TextView tvHotelName;
        @Bind(R.id.tv_order_num)
        TextView tvOrderNum;
        @Bind(R.id.btn_into_hotel)
        Button btnIntoHotel;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
